﻿using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web;
using CTS.Com.Domain.Helper;

namespace CTS.Web.Com.Domain.Helper
{
    public static class WebFileHelper
    {
        /// <summary>
        /// Read file into a string
        /// </summary>
        /// <param name="path">Path</param>
        /// <returns>Content of file</returns>
        public static string ToString(string path)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            //Return value
            return FileHelper.ToString(strPath);
        }

        /// <summary>
        /// Save file
        /// </summary>
        /// <param name="stream">stream</param>
        /// <param name="path">Path</param>
        public static void SaveFile(Stream stream, string path)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // Save file
            FileHelper.SaveFile(stream, strPath);
        }

        /// <summary>
        /// Delete file
        /// </summary>
        /// <param name="path">Path</param>
        /// <returns>True/False</returns>
        public static bool DeleteFile(string path)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // Delete file
            return FileHelper.DeleteFile(strPath);
        }

        /// <summary>
        /// Move file
        /// </summary>
        /// <param name="sourcePath">SourcePath</param>
        /// <param name="targetPath">TargetPath</param>
        public static void MoveFile(string sourcePath, string targetPath)
        {
            // Local variable declaration
            var strSourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            var strTargetPath = HttpContext.Current.Server.MapPath(targetPath);
            // Move file
            FileHelper.MoveFile(strSourcePath, strTargetPath);
        }

        /// <summary>
        /// Move files
        /// </summary>
        /// <param name="sourcePath">SourcePath</param>
        /// <param name="targetPath">TargetPath</param>
        /// <param name="ext">Extension</param>
        public static void MoveFiles(string sourcePath, string targetPath, string ext)
        {
            // Local variable declaration
            var strSourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            var strTargetPath = HttpContext.Current.Server.MapPath(targetPath);
            // Move file
            FileHelper.MoveFiles(strSourcePath, strTargetPath, ext);
        }

        /// <summary>
        /// Copy files
        /// </summary>
        /// <param name="sourcePath">SourcePath</param>
        /// <param name="targetPath">TargetPath</param>
        /// <param name="ext">Extension</param>
        public static void CopyFiles(string sourcePath, string targetPath, string ext)
        {
            // Local variable declaration
            var strSourcePath = HttpContext.Current.Server.MapPath(sourcePath);
            var strTargetPath = HttpContext.Current.Server.MapPath(targetPath);
            // Move files
            FileHelper.CopyFiles(strSourcePath, strTargetPath, ext);
        }

        /// <summary>
        /// Delete files
        /// </summary>
        /// <param name="path">Path</param>
        /// <param name="ext">Extension</param>
        public static void DeleteFiles(string path, string ext)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // Delete files
            FileHelper.DeleteFiles(strPath, ext);
        }

        /// <summary>
        /// Get files
        /// </summary>
        /// <param name="path">Path</param>
        /// <param name="ext">Extension</param>
        /// <returns>Files</returns>
        public static IList<FileInfo> GetFiles(string path, string ext)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // return value
            return FileHelper.GetFiles(strPath, ext);
        }

        /// <summary>
        /// Exist files
        /// </summary>
        /// <param name="path">Path</param>
        /// <param name="ext">Extension</param>
        /// <returns>True/False</returns>
        public static bool ExistFiles(string path, string ext)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // return value
            return FileHelper.ExistFiles(strPath, ext);
        }

        /// <summary>
        /// Save image
        /// </summary>
        /// <param name="img">Image</param>
        /// <param name="path">Path</param>
        /// <param name="format">ImageFormat</param>
        public static void SaveImage(Image img, string path, ImageFormat format)
        {
            // Local variable declaration
            var strPath = HttpContext.Current.Server.MapPath(path);
            // Save
            ImageHelper.Save(img, strPath, format);
        }
    }
}
